package com.lj.demo.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lj.demo.eduservice.entity.EduTeacher;
import com.lj.demo.eduservice.mapper.EduTeacherMapper;
import com.lj.demo.eduservice.query.QueryTeacher;
import com.lj.demo.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-11-15
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    //分页查询讲师列表
    @Override
    public Map<String, Object> getPageList(Page<EduTeacher> pageTeacher) {
       QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
       queryWrapper.orderByAsc("sort");

       baseMapper.selectPage(pageTeacher,queryWrapper);

        List<EduTeacher> records = pageTeacher.getRecords();
        long current = pageTeacher.getCurrent();
        long pages = pageTeacher.getPages();
        long size = pageTeacher.getSize();
        long total = pageTeacher.getTotal();
        boolean hasNext = pageTeacher.hasNext();
        boolean hasPrevious = pageTeacher.hasPrevious();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("items", records);
        map.put("current", current);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);
        return map;
    }


//    @Override
//    public void pageQuery(Page<EduTeacher> pageParam, QueryTeacher queryTeacher) {
//
//        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByAsc("sort");
//
//        if (queryTeacher == null){
//            baseMapper.selectPage((IPage<EduTeacher>) pageParam,queryWrapper);
//            return;
//        }
//
//
//
//
//    }
}
